<!DOCTYPE html>
<html xmlns:javascript="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>首页</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style type="text/css">
        #zhong {
            display: inline-block;

            text-align: left;
            padding-left: 70px;
            align-items: center;
        }

        label {
            display: block;
        }

        label span {
            display: inline-block;

            width: 80px;
            text-align: right;
            margin-right: 30px;
        }
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">

        <div class="layui-logo">小熊CRM</div>
        <ul class="layui-nav layui-layout-right" lay-filter="test">

            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="../img/6.png" class="layui-nav-img">
                    <span id="user">请登录</span>
                </a>
                <!--隐藏域,接收登陆者的id-->
                <div id="userid" style="display: none"></div>
                <dl class="layui-nav-child">
                    <dd id="message"><a href="###" data-index="message_me.html">基本资料</a></dd>
                    <dd id="change"><a href="javascript:;">修改密码</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="login.html">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item">
                    <a href="javascript:;" data-index="panel.html">数据一览</a>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">客户管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-index="clue1.html">线索</a></dd>
                        <dd><a href="javascript:;" data-index="customer1.html">客户</a></dd>
                        <dd><a href="javascript:;" data-index="linkMan1.html">联系人</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <dd><a href="javascript:;" data-index="contract1.html">合同</a></dd>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;" data-index="approve.html">审批</a>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">通讯录</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-index="address_book.html">全部</a></dd>
                        <dd><a href="javascript:;" data-index="focus.html">我的关注</a></dd>
                    </dl>
                </li>
                <li id="userManager"  class="layui-nav-item">
                    <a  href="javascript:;" data-index="management.html">员工管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">市场活动</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-index="activity.html">活动信息</a></dd>
                    </dl>
                </li>

            </ul>
        </div>
    </div>
    <div id="zhong" style=" display: none; width: 350px; height: 200px; font-size: 18px; ">

        <form action="../user/updateUserPassword" method="post">
            <label><br/><br/>
                <span> <font color="red">*</font>原密码</span> <input id="old" value="" layui type="password" name="old"
                                                                   style="width: 220px; height: 30px; border: solid 1px gainsboro;"/><br/><br/>

                <span> <font color="red">*</font>新密码</span> <input id="new" value="" type="password" name="new"
                                                                   style="width: 220px; height: 30px; border: solid 1px gainsboro;"/><br/><br/>

                <span> <font color="red">*</font>确认密码</span> <input id="affirm" value="" type="password" placeholder=""
                                                                    name="affirm"
                                                                    style="width: 220px; height: 30px; border: solid 1px gainsboro;"/><br/><br/>

            </label>
            <input type="submit" id="subim" style="display: none; " value="提交"/>

        </form>
    </div>


    <div class="layui-body">
        <!-- 内容主体区域 -->

        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show" style="height: 100% ;">
                <iframe src="panel.html" frameborder="0" class="layadmin-iframe"
                        style="width: 100%;height: 100%;"></iframe>
            </div>
        </div>


    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © CRM.com - 小熊CRM
    </div>
</div>

<script type="text/javascript" src="../layui/layui.all.js"></script>
<script src="../js/jquery.min.js"></script>

<!--得到登录后的名字-->
<script>
    $(function () {

        $.ajax({
            url: "../login/getUsername",
            type: "post",
            data: {},
            success: function (data) {
                var username = data.username;
                var userid = data.userid;
                sessionStorage.setItem("username", username);
                sessionStorage.setItem("userid", userid);

                if (userid!=1){
                    console.log(userid);
                    console.log(username);
                    $("#userManager").addClass("layui-hide");
                }

                $("#userid").text(sessionStorage.getItem("userid"));
                $("#user").text(sessionStorage.getItem("username"));

                if (sessionStorage.getItem("username")=="undefined"||sessionStorage.getItem("username")=="") {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg("登录失效，请重新登录！");
                        setTimeout(function() {
                            location.href='http://localhost:8080/CRM_war/pages/login.html';
                        }, 2 * 1000);
                    })
                }
                $("#message a").attr("data-index", "message_me.html?" +
                    "username=" + username + "&userid=" + userid);
            }
        });
    });
</script>

<script>
    layui.use('element', function () {
        var element = layui.element;

        $(".layui-layout-body a").each(function (index, el) {
            $(el).click(function () {
                $(".layui-body iframe").attr("src", $(this).attr("data-index"))

            })
        })
    });


    $("#change").on("click", function () {
        layer.open({
            title: '修改密码',
            type: 1,
            content: $("#zhong"),
            skin: 'layui-layer-molv',
            area: ['500px', '300px'],
            btn: ['确定', '取消'],
            shade: [0.7, '#393D49'],
            anim: 1,
            yes: function (index, layero) {
                //按钮【按钮一】的回调
                if ($("#new").val() != "" && $("#affirm").val() && $("#old").val()) {
                    if ($("#new").val() == $("#affirm").val()) {

                        $.ajax({
                            url: '../user/updateUserPassword',
                            type: 'post',
                            data: {
                                oldpassword: $("#old").val(),
                                newpassword: $("#affirm").val()

                            }, //向服务端发送新密码和旧密码
                            success: function (suc) {
                                if (suc == 200) {
                                    layer.close(index);
                                    console.log(index);
                                    layer.msg("修改成功", {
                                        icon: 1
                                    });
                                } else {
                                    layer.msg("修改失败", {
                                        icon: 5
                                    });
                                }
                            }
                        });
                        layer.close(index);

                        $("#old").val("")
                        $("#new").val("")
                        $("#affirm").val("")

                        $("#zhong").css("display", "none");  //重新隐藏表单
                    } else {
                        layer.msg("两次密码不一致,修改失败")
                    }
                } else {
                    layer.msg("密码不能为空!")
                    $("#new").val("")
                }

            }
            , btn2: function (index, layero) {
                //按钮【按钮二】的回调
                $("#old").val("")
                $("#new").val("")
                $("#affirm").val("")
                $("#zhong").css("display", "none");
            }

            , cancel: function () {
                //右上角关闭回调
                $("#old").val("")
                $("#new").val("")
                $("#affirm").val("")
                $("#zhong").css("display", "none");
            }
        });
    });


</script>


</body>
</html>